package io.adrainty.algorithm.mars;

/**
 * 最少字符串操作次数
 * @link <a href="https://www.marscode.cn/practice/364l85wv6oo6lq?problem_id=7424436653623017516">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @since 2024/11/30 下午5:32
 */
public class Solution022 {

    public static int solution(String S) {
        // write code here
        int[] map = new int[26];
        for (char cs : S.toCharArray()) {
            map[cs - 'a']++;
        }
        int count = 0;
        for (int i = 0; i < 26; i++) {
            if (map[i] > 1) count += map[i] / 2;
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(solution("abab") == 2);
        System.out.println(solution("aaaa") == 2);
        System.out.println(solution("abcabc") == 3);
    }

}
